﻿using System.Windows.Data;
using SABnzbdNET.Commands;
using SABnzbdNET.Model;

namespace SABnzbdNET.Converters
{
    public class IsCheckedConverter : IMultiValueConverter 
    {
        public object Convert(object[] values, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Job job = null;
            string param = string.Empty;
            foreach (var value in values)
            {
                if(value is Job)
                    job = value as Job;
                if (value is string)
                    param = value as string;
            }
            
            if(job != null)
            {
                switch (((string)parameter).ToLower())
                {
                    case "'priority'":
                        return (job.Priority.Equals(param, System.StringComparison.OrdinalIgnoreCase));
                    case "'processing'":
                        {
                            switch (param.ToLower())
                            {
                                case "download":
                                    return job.Processing == 0;
                                case "+repair":
                                    return job.Processing == 1;
                                case "+unpack":
                                    return job.Processing == 2;
                                case "+delete":
                                    return job.Processing == 3;
                                default:
                                    return false;
                            }
                        }
                }
            }
            return null;
        }

        public object[] ConvertBack(object value, System.Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new System.NotImplementedException();
        }
    }
}
